// 将app.globalData注入到所有页面的data.$globalData中
// 并提供this.$global.setData的方法修改 globalData

let appInstance = null;

function $hasPermission(str, { tip } = {}) {
  // console.assert(str !== undefined, "需要传入权限对应的字符串");
  let permit = appInstance.globalData.permissions[str] || false;
  if (tip && !permit)
    wx.showToast({
      title: "黄金会员可使用此功能，会员购买或升级请联系龙小姐：18922938768",
      icon: "none"
    });
  return permit;
}

export default {
  App: {
    onLaunch() {
      appInstance = this;
    }
  },
  Page: {
    $hasPermission
  },
  //Component Object
  Component: {
    methods: {
      $hasPermission
    }
  }
};
